
#include <assert.h>
#include "Material.h"

/*
namespace FlameEngine
{
	void Material::SetParam(std::shared_ptr<UniqueString> name,float value)
	{
		for(uint32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				ParamInfo& paramInfo = m_paramInfos[i];
				m_paramData[paramInfo.m_paramIndex] = value;
				return;
			}
		}

		int32_t index = m_paramInfos.size();
		m_paramInfos.push_back(ParamInfo(name,index,1));
		m_paramData.push_back(value);
	}

	void Material::SetParam(std::shared_ptr<UniqueString> name,const DirectX::XMFLOAT2& value)
	{
		for(uint32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				ParamInfo& paramInfo = m_paramInfos[i];
				if(paramInfo.m_paramLength >=2)
				{
					m_paramData[paramInfo.m_paramIndex] = value.x;
					m_paramData[paramInfo.m_paramIndex+1] = value.y;
				}
				else if(paramInfo.m_paramLength == 1)
				{
					m_paramData[paramInfo.m_paramIndex] = value.x;
				}
				return;
			}
		}

		int32_t index = m_paramInfos.size();
		m_paramInfos.push_back(ParamInfo(name,index,2));
		m_paramData.push_back(value.x);
		m_paramData.push_back(value.y);
	}

	void Material::SetParam(std::shared_ptr<UniqueString> name,const DirectX::XMFLOAT3& value)
	{
		for(uint32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				ParamInfo& paramInfo = m_paramInfos[i];
				if(paramInfo.m_paramLength >=3)
				{
					m_paramData[paramInfo.m_paramIndex] = value.x;
					m_paramData[paramInfo.m_paramIndex+1] = value.y;
					m_paramData[paramInfo.m_paramIndex+2] = value.z;
				}
				if(paramInfo.m_paramLength ==2)
				{
					m_paramData[paramInfo.m_paramIndex] = value.x;
					m_paramData[paramInfo.m_paramIndex+1] = value.y;
				}
				else if(paramInfo.m_paramLength == 1)
				{
					m_paramData[paramInfo.m_paramIndex] = value.x;
				}
				return;
			}
		}

		int32_t index = m_paramInfos.size();
		m_paramInfos.push_back(ParamInfo(name,index,3));
		m_paramData.push_back(value.x);
		m_paramData.push_back(value.y);
		m_paramData.push_back(value.z);
	}

	void Material::SetParam(std::shared_ptr<UniqueString> name,const DirectX::XMFLOAT4& value)
	{
		for(uint32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				ParamInfo& paramInfo = m_paramInfos[i];
				if(paramInfo.m_paramLength >=4)
				{
					m_paramData[paramInfo.m_paramIndex] = value.x;
					m_paramData[paramInfo.m_paramIndex+1] = value.y;
					m_paramData[paramInfo.m_paramIndex+2] = value.z;
					m_paramData[paramInfo.m_paramIndex+3] = value.w;
				}
				else if(paramInfo.m_paramLength == 3)
				{
					m_paramData[paramInfo.m_paramIndex] = value.x;
					m_paramData[paramInfo.m_paramIndex+1] = value.y;
					m_paramData[paramInfo.m_paramIndex+2] = value.z;

				}
				else if(paramInfo.m_paramLength ==2)
				{
					m_paramData[paramInfo.m_paramIndex] = value.x;
					m_paramData[paramInfo.m_paramIndex+1] = value.y;
				}
				else if(paramInfo.m_paramLength == 1)
				{
					m_paramData[paramInfo.m_paramIndex] = value.x;
				}
				return;
			}
		}

		int32_t index = m_paramInfos.size();
		m_paramInfos.push_back(ParamInfo(name,index,4));
		m_paramData.push_back(value.x);
		m_paramData.push_back(value.y);
		m_paramData.push_back(value.z);
		m_paramData.push_back(value.w);
	}

	void Material::SetParam(std::shared_ptr<UniqueString> name,const float* value,int32_t dataLength)
	{
		for(uint32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				ParamInfo& paramInfo = m_paramInfos[i];
				if(dataLength > paramInfo.m_paramLength)
					dataLength = paramInfo.m_paramLength;
				memcpy(&m_paramData[paramInfo.m_paramIndex],value,dataLength*sizeof(float));
				return;
			}
		}

		int32_t index = m_paramInfos.size();
		m_paramInfos.push_back(ParamInfo(name,index,dataLength));
		for(int32_t i=0;i<dataLength;i++)
		{
			m_paramData.push_back(*value);
			value++;
		}
	}

	void Material::GetParam(const UniqueString* name,float& oValue) const
	{
		for(uint32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				const ParamInfo& paramInfo = m_paramInfos[i];
				oValue = m_paramData[paramInfo.m_paramIndex];
				return;
			}
		}
		oValue = 0;
	}

	void Material::GetParam(const UniqueString* name,DirectX::XMFLOAT2& oValue) const
	{
		for(uint32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				const ParamInfo& paramInfo = m_paramInfos[i];
				if(paramInfo.m_paramLength >= 2)
				{
					oValue.x = m_paramData[paramInfo.m_paramIndex];
					oValue.y = m_paramData[paramInfo.m_paramIndex+1];
				}
				else
				{
					oValue.x = m_paramData[paramInfo.m_paramIndex];
					oValue.y = 0;
				}
				return;
			}
		}
		oValue.x = 0;
		oValue.y = 0;
		return;
	}

	void Material::GetParam(const UniqueString* name,DirectX::XMFLOAT3& oValue) const
	{
		for(uint32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				const ParamInfo& paramInfo = m_paramInfos[i];
				if(paramInfo.m_paramLength >= 3)
				{
					oValue.x = m_paramData[paramInfo.m_paramIndex];
					oValue.y = m_paramData[paramInfo.m_paramIndex+1];
					oValue.z = m_paramData[paramInfo.m_paramIndex+2];
				}
				else if(paramInfo.m_paramLength == 2)
				{
					oValue.x = m_paramData[paramInfo.m_paramIndex];
					oValue.y = m_paramData[paramInfo.m_paramIndex+1];
					oValue.z = 0;
				}
				else if(paramInfo.m_paramLength == 1)
				{				
					oValue.x = m_paramData[paramInfo.m_paramIndex];
					oValue.y = 0;
					oValue.z = 0;
				}
				return;
			}
		}
		oValue.x = 0;
		oValue.y = 0;
		oValue.z = 0;
		return;
	}

	void Material::GetParam(const UniqueString* name,DirectX::XMFLOAT4& oValue) const
	{
		for(int32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				const ParamInfo& paramInfo = m_paramInfos[i];
				if(paramInfo.m_paramLength >= 4)
				{
					oValue.x = m_paramData[paramInfo.m_paramIndex];
					oValue.y = m_paramData[paramInfo.m_paramIndex+1];
					oValue.z = m_paramData[paramInfo.m_paramIndex+2];
					oValue.w = m_paramData[paramInfo.m_paramIndex+3];
				}
				else if(paramInfo.m_paramLength == 3)
				{
					oValue.x = m_paramData[paramInfo.m_paramIndex];
					oValue.y = m_paramData[paramInfo.m_paramIndex+1];
					oValue.z = m_paramData[paramInfo.m_paramIndex+2];
					oValue.w = 0;
				}
				else if(paramInfo.m_paramLength == 2)
				{
					oValue.x = m_paramData[paramInfo.m_paramIndex];
					oValue.y = m_paramData[paramInfo.m_paramIndex+1];
					oValue.z = 0;
					oValue.w = 0;
				}
				else if(paramInfo.m_paramLength == 1)
				{
					oValue.x = m_paramData[paramInfo.m_paramIndex];
					oValue.y = 0;
					oValue.z = 0;
					oValue.w = 0;
				}
				return;
			}
		}
		oValue.x = 0;
		oValue.y = 0;
		oValue.z = 0;
		oValue.w = 0;
		return;
	}

	void Material::GetParam(const UniqueString* name,float* oValue,int32_t count) const
	{
		for(int32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				const ParamInfo& paramInfo = m_paramInfos[i];
				if(count > paramInfo.m_paramLength)
					count = paramInfo.m_paramLength;
				memcpy(oValue,&m_paramData[paramInfo.m_paramIndex],count*sizeof(float));
				return;
			}
		}
		memset(oValue,0,sizeof(float));
	}

	bool Material::HasParam(const UniqueString* name)
	{
		for(int32_t i=0;i<m_paramInfos.size();i++)
		{
			if(m_paramInfos[i].m_Name->GetID() == name->GetID())
			{
				return true;
			}
		}
		return false;
	}
}
*/